package custom.cards;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Window;

public class SplashScreen extends Activity {
	
    // properties for splash screen
    private final double _splashTime = 2500; //originally 300, 1500
    private final Activity activity = this;
    MediaPlayer shuffle;
    
	@Override
    public void onCreate(Bundle savedInstanceState)
    {

		shuffle =  MediaPlayer.create(this, R.raw.shuffling);
        shuffle.start();
		super.onCreate(savedInstanceState);
		
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.splash_screen);
		this.setTitle(" Loading...");
		
		new LoadingTask().execute();	
    }
	
	 public void onDestroy() {

         shuffle.stop();
         shuffle.release();
         super.onDestroy();


     }
	
	 private class LoadingTask extends AsyncTask<Void, Integer, Integer> 
     {
	     protected void onProgressUpdate(Integer... progress) 
	     {
		
	         activity.setProgress(progress[0]);
	     }
	     protected void onPostExecute(Integer result) 
	     {
		    finish();
		    startActivity(new Intent(activity, MainActivity.class));
	     }

	    @Override
	    protected Integer doInBackground(Void... params)
	    {
		//Logger.deleteLogFile();	
			try
			{
			    double waited = 0;
			    while (waited < _splashTime)
			    {				    
				    waited += 10;
				    double prog = (waited/_splashTime)*10000;
				    publishProgress((int)prog);				    
				    Thread.sleep(10);				
			    }
			}
			catch (InterruptedException e)
			{
			    return -1;
			}
			
		return 0;
	    }	   
	 }
}


